package com.bitin.adorn.common.plugin;

import com.bitin.adorn.common.annotation.Phone;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.springframework.util.StringUtils;

/**
 * @author Mr.Lu
 * @since 2024/12/5 17:25
 */
public class PhoneValidator implements ConstraintValidator<Phone, String> {

    @Override
    public boolean isValid(String phone, ConstraintValidatorContext constraintValidatorContext) {
        if(!StringUtils.isEmpty(phone)){
            String regex = "^1(3|4|5|6|7|8|9)\\d{9}$";
            return phone.matches(regex);
        }
        return true;
    }
}
